<?php

namespace app\admin\model;

use think\Model;

class Githouse extends Model
{
    // 表名
    protected $name = 'githouse';
    
    // 自动写入时间戳字段
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'ctime';
    protected $updateTime = false;



    // 追加属性
    protected $append = [
        'status_text',
        'ctime_text',
        'dep_text'
    ];

    public function getProvinceList()
    {
        $areaList =  Area::getArea();
        return $areaList;
    }



    public function getStatusList()
    {
        return ['1' => __('Status 1'),'0' => __('Status 0')];
    }
    public function getDepartmentList(){
        return array_column(collection(model(GetTableModel('AuthDepartment'))::field('id,name,delete_status')->select())->toArray(), 'name','id');
    }

    public function getCtimeAttr($value, $data)
    {
        return date("Y-m-d H:i:s",$value);
    }

    public function getDepTextAttr($value, $data)
    {
       /* $value = $value ? $value : $data['dep'];
        if ($value==0)return '';
        $list = $this->getDepartmentList();
        $arr = explode(',',$value);

        foreach ($arr as $value)
        {
            $str[] = $list[$value];
        }

        $str  = implode(',', $str);*/
        return  $data['gname'];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCtimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['ctime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCtimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
